package com.fas.app.entity;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CenterItem extends LinearLayout {
	private Context context;
	private boolean hasImage;
	
	private TextView text;
	private ImageView image;
	public CenterItem(Context context,boolean hasImage) {
		super(context);
		this.hasImage = hasImage;
		this.context = context;
		initLayout();
	}

	public CenterItem(Context context, AttributeSet attrs,boolean hasImage) {
		super(context, attrs);
		this.context = context;
		this.hasImage = hasImage;
		initLayout();
	}

	private void initLayout() {
		this.setOrientation(LinearLayout.VERTICAL);
		if(hasImage) {
			LinearLayout.LayoutParams textLP = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
			textLP.gravity = Gravity.CENTER_HORIZONTAL;
			TextView text = new TextView(context);
			this.text = text;
			text.setTextColor(Color.BLACK);
			text.setTextSize(16.f);
			addView(text,textLP);
			
			LinearLayout.LayoutParams imageLP = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
			imageLP.gravity = Gravity.CENTER_HORIZONTAL;
			ImageView image = new ImageView(context);
			this.image = image;
			addView(image,imageLP);
		}else {
			LinearLayout.LayoutParams textLP = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
			textLP.gravity = Gravity.CENTER_HORIZONTAL;
			TextView text = new TextView(context);
			this.text = text;
			text.setGravity(Gravity.CENTER_HORIZONTAL);
			text.setTextSize(40.f);
			text.setTextColor(Color.BLACK);
			addView(text,textLP);
		}
	}
	
	public void setItemText(int textid) {
		if(text!=null) {
			text.setTextSize(40.f);
			text.setText(context.getResources().getString(textid));
		}
	}
	
	public void setItemImage(int imageid) {
		if(image!=null) {
			image.setImageResource(imageid);
		}
	}

}
